import cv2
capture=cv2.VideoCapture(0)
while(capture.isOpened()):
    retval,image=capture.read()
    cv2.imshow("Video",image)
    key=cv2.waitKey(1)
    if key==32:
        break
capture.release()
cv2.destroyAllWindows()

import cv2
video=cv2.VideoCapture("yzbf.mp4")
while(video.isOpened()):
    retval,image=video.read()
    cv2.namedWindow("Video",0)
    cv2.resizeWindow("Video",420,300)
    if retval==True:
        cv2.imshow("Video",image)
    else:
        break
    key=cv2.waitKey(1)
    if key==27:
        break
video.release()
cv2.destroyAllWindows()

import cv2
video=cv2.VideoCapture("yzbf.mp4")
fps=video.get(cv2.CAP_PROP_FPS)
frame_count=video.get(cv2.CAP_PROP_FRAME_COUNT)
frame_width=video.get(cv2.CAP_PROP_FRAME_WIDTH)
frame_height=video.get(cv2.CAP_PROP_FRAME_HEIGHT)
print("帧速率:",fps)
print("帧数:",frame_count)
print("帧的宽度:",frame_width)
print("帧的高度:",frame_height)

import cv2
video=cv2.VideoCapture("landscape.avi")
fps=video.get(cv2.CAP_PROP_FPS)
size=(int(video.get(cv2.CAP_PROP_FRAME_WIDTH)),int(video.get(cv2.CAP_PROP_FRAME_HEIGHT)))
fource=cv2.VideoWriter_fourcc(*'XVID')
output=cv2.VideoWriter("out.avi",fource,fps,size)
while(video.isOpened()):
    retval,frame=video.read()
    if retval:
        output.write(frame)
    else:
        break
print("视频已保存")
video.release()
output.release()